/**
* @description: 223. 矩形面积
* @author hewei
* @date 2022/7/29 16:03
* @version 1.0
*/

public class ComputeArea {

    public int computeArea(int ax1, int ay1, int ax2, int ay2, int bx1, int by1, int bx2, int by2) {
        int area1 = Math.abs(ax1 - ax2) * Math.abs(ay1 - ay2);
        int area2 = Math.abs(bx1 - bx2) * Math.abs(by1 - by2);
        if (Math.max(ax1, bx1) >= Math.min(bx2, ax2) || Math.max(ay1, by1) >= Math.min(by2, ay2)) return area1 + area2;
        return area1 + area2 - (Math.min(bx2, ax2) - Math.max(ax1, bx1)) * (Math.min(by2, ay2) - Math.max(ay1, by1));
    }
}
